package com.mybatisflex.example.mapper.taos;

import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.example.pojo.domain.taos.Temperature;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@UseDataSource("taos")
public interface TemperatureMapper extends BaseMapper<Temperature> {

    @Update("CREATE TABLE if not exists temperature(ts timestamp, temperature float) tags (district_name  nchar(30),district_code int)")
    int createSuperTable();

    @Update("create table temperature_#{districtCode} using temperature tags( #{districtName},#{districtCode})")
    int createTable(@Param("districtName") String districtName, @Param("districtCode") Integer districtCode);

    @Update("drop table if exists temperature")
    void dropSuperTable();

    @Insert("INSERT INTO temperature_#{districtCode} USING temperature TAGS(#{districtName} ,#{districtCode}) VALUES (#{ts}, #{temperature})")
    int insertOne(Temperature temperature);

}
